package controller

import (
	"gin-study/response"
	"gin-study/service"
	"github.com/gin-gonic/gin"
	"net/http"
)

/*
*
手动注入
*/
type HelloController struct {
	helloService *service.HelloService
}

func NewHelloController() *HelloController {
	return &HelloController{
		helloService: service.NewHelloService(),
	}
}

func (h *HelloController) SayHello(c *gin.Context) {
	name := c.Query("name")
	if name == "" {
		name = "World"
	}

	message := h.helloService.GetHelloMessage(name)
	c.JSON(http.StatusOK, response.Success(message))
}

func (h *HelloController) SayHelloToUser(c *gin.Context) {
	name := c.Param("name")
	message := h.helloService.GetPersonalizedMessage(name)
	c.JSON(http.StatusOK, response.Success(message))
}
